﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
//using System.Xml.Linq;

using YouHP.BLL;
using YouHP.Model;
using YouHP.Model.Group;
using YouHP.Utility;
using System.Data.SqlTypes;

namespace web.admin
{
    public partial class HyperLinkListEdit : System.Web.UI.Page
    {
        private HyperLinkBLL hyperLinkBll = HyperLinkBLL.Instance;
        private static HyperLinkInfo hyperLinkInfo = new HyperLinkInfo();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
            
        }
        protected void CancelButton_click(object sender, EventArgs e)
        {
            Response.Redirect("HyperLinkList.aspx");
        }
        protected void InsertButton_click(object sender, EventArgs e)
        {
            HyperLinkInfo updateHyperLinkInfo = validateForm(hyperLinkInfoEdit);
            bool succ = hyperLinkBll.UpdateHyperLink(updateHyperLinkInfo);
            Response.Redirect("HyperLinkList.aspx");
        }
        protected void DataBound(object sender, EventArgs e)
        {

        }
        protected void Bind()
        {
            try
            {
                int id = RequestTools.GetQueryInt("id", -1);
                if (id > 0)
                {
                    IList list = new ArrayList();
                    hyperLinkInfo = hyperLinkBll.GetHyperLink(id);
                    list.Add(hyperLinkInfo);
                    this.hyperLinkInfoEdit.DataSource = list;
                    this.hyperLinkInfoEdit.DataBind();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private HyperLinkInfo validateForm(DetailsView formViewCtl)
        {
            HyperLinkInfo updatedHyperLinkInfo = new HyperLinkInfo();
            updatedHyperLinkInfo.Id = hyperLinkInfo.Id;
            updatedHyperLinkInfo.Title = ((TextBox)formViewCtl.FindControl("title")).Text;
            updatedHyperLinkInfo.IsLogo = false;
            updatedHyperLinkInfo.Brif = ((TextBox)formViewCtl.FindControl("introduction")).Text;
            updatedHyperLinkInfo.CreateTime = hyperLinkInfo.CreateTime;
            updatedHyperLinkInfo.LastUpdateTime = DateTime.Now;

            //updatedNewsInfo.Body = ((TextBox)formViewCtl.FindControl("body")).Text;
            return updatedHyperLinkInfo;
        }
    }
}
